<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Login Page</title>
		<!-- 样 式 文 件 -->
		<link rel="stylesheet" href="static/component/pear/css/pear.css"/>
		<link rel="stylesheet" href="static/admin/css/other/login.css" />
	</head>
    <!-- 代 码 结 构 -->
	<body background="static/admin/images/background2.svg" style="background-size: cover;">
	<!--javascript:void(0);-->
		<form class="layui-form" lay-filter="addform" action="" >
			<div class="layui-form-item">
				<img class="logo" src="static/admin/images/logo.png" />
				<div class="title">欢迎登陆</div>
				<div class="desc">
					<!--有道无术，术尚可求也，有术无道 止于术-->
					“万事都作糊涂观,无所谓失,无所谓得”
				</div>
			</div>
			<div class="layui-form-item">
				<input placeholder="账 户 : admin " hover class="layui-input name" value="" name="name" required="required"/>
			</div>
			<div class="layui-form-item">
				<input placeholder="密 码 : pwd " hover class="layui-input pwd"  value="" name="pwd" required="required"/>
			</div>
			<div class="layui-form-item">
				<input placeholder="验证码 : "  hover class="code layui-input layui-input-inline yzm" value="" name="yzm" required="required" />
				<img src="/getAuthCodeImg?count=0" id="authCodeImg" onclick="changeCodeImg(this)"  class="codeImage" width="115px">
				<!--<img src="static/admin/images/captcha.gif" class="codeImage">-->
			</div>
			<div class="layui-form-item">
				<span style="color:red" class="info"></span>
			</div>
			<div class="layui-form-item">
				<input type="checkbox" name="" title="记住密码" lay-skin="primary" checked>
			</div>
			<div class="layui-form-item">
				<button type="button" class="pear-btn pear-btn-success login" lay-submit lay-filter="login">
					登 入
				</button>
			</div>
		</form>

		<!-- 资 源 引 入 -->
		<script src="static/component/layui/layui.js"></script>
		<script src="static/component/pear/pear.js"></script>
		<script>
			layui.use(['form','element','jquery','button','popup'], function() {
				let form = layui.form;
				let element = layui.element;
				let button = layui.button;
				let popup = layui.popup;
				let $ = layui.jquery;
                // 登 录 提 交
				form.on('submit(login)', function(data) {
					//表单值
					let parms=  form.val("addform")
					if($(".name").val()==""){
						$(".info").html("姓名不能为空")
						return;
					}
					if($(".pwd").val()==""){
						$(".info").html("密码不能为空")
						return;
					}
					if($(".yzm").val()==""){
						$(".info").html("验证码不能为空")
						return;
					}
					$.ajax({
						url:"/login",
						type:"post",
					    data:parms,
						dataType:"json"
						,success:function (data) {
							alert("aa"+data)
							if(data=="成功"){
								popup.success("登录成功", function(){
									location.href="/index"
								});
							}else if(data=="验证码错误-请重新输入验证码") {
                                console.log("这范围")
								$(".info").html("验证码错误-请重新输入验证码")
							}else{
								popup.success("登录失败", function(){
								});
							}
					   }
				    })
					/**
					 * 模板项目遗留代码不想删可能会用到
					 * 	button.load({
						elem:'.login',
						time: 1500,
						done: function() {
							popup.success("登录成功", function() {
								// location.href = "index.html"
							});
						}
					   })
					   return false;
					 */
				});
			});
			function changeCodeImg(codeImg){
				codeImg.src = "/getAuthCodeImg?count=1&timestamp="+new Date().getTime();
			}
		</script>
	</body>
</html>
